package homework_4.write_1;

public class Triangle {
    public double a;
    public double b;
    public double c;

    public Triangle(double a, double b, double c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double area(){
        if( a > 0 && b > 0 && c > 0 && a+b > c && a+c >b && b+c >a){
            double p = (a+b+c)/2;
            System.out.println(Math.sqrt(p * (p-a) * (p-b) * (p-c)));
            return Math.sqrt(p * (p-a) * (p-b) * (p-c));
        }
        else try {
            throw new NotTriangle("非三角形");
        } catch (NotTriangle e) {
            System.out.println(e.getMessage());
            return -1;
        }
    }

    public static void main(String[] args) {
        Triangle test_1 = new Triangle(3.0,4.0,5.0);
        Triangle test_2 = new Triangle(1.0,1.0,2.0);

        test_1.area();
        test_2.area();


    }

}
